﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPandDatabases
{
    public partial class StartPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ListBoxCountries_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GridViewCountries.Visible = true;
            this.ListViewTowns.Visible = false;
        }

        protected void GridViewCountries_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.TownsDataSource.Where = "it.CountryID = " + this.GridViewCountries.SelectedValue;
            this.ListViewTowns.Visible = true;
        }

        protected void ButtonInsertTown_Click(object sender, EventArgs e)
        {
            InsertItemPosition currnetPosition = this.ListViewTowns.InsertItemPosition;
            if (currnetPosition == InsertItemPosition.None)
            {
                this.ListViewTowns.InsertItemPosition = InsertItemPosition.LastItem;
            }
            else
            {
                this.ListViewTowns.InsertItemPosition = InsertItemPosition.None;
            }
        }

        protected void ListViewTowns_ItemInsert(object sender, EventArgs e)
        {
            InsertItemPosition currnetPosition = this.ListViewTowns.InsertItemPosition;
            if (currnetPosition == InsertItemPosition.None)
            {
                this.ListViewTowns.InsertItemPosition = InsertItemPosition.LastItem;
            }
            else
            {
                this.ListViewTowns.InsertItemPosition = InsertItemPosition.None;
            }
        }
    }
}